<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">巡检设置</block>
		</cu-custom>
		<form>
			<view class="cu-form-group">
				<view class="title">巡线采集频率(秒):</view>
				<input  name="input" v-model="myFormData.arate" @input="numberFixedDigit"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">基准采集频率(秒):</view>
				<input  name="input" v-model="myFormData.rrate" @input="numberFixedDigitR"></input>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: -1,
				switchC: true,
				type:"1",
				myFormData:{
					arate:'',
					rrate:'',
				},
			};
		},
		onLoad: function (option) {
			var that=this;
	       this.$http.get("/api/v1/appbusiness/two/getConfig",{params:{}}).then(res=>{
	       			if (res.data.success){
	       				that.myFormData.arate=res.data.result.arate
						that.myFormData.rrate=res.data.result.rrate																								
	                  }	   			
	       })
		},
		methods: {
			numberFixedDigit (e) { // 只能输入整数
			  e.target.value = e.target.value.replace(/^0|[^\d]|[.]/g, '')
			  this.$nextTick(() => {
			    this.myFormData.arate= e.target.value
			  })
			},
			numberFixedDigitR (e) { // 只能输入整数
			  e.target.value = e.target.value.replace(/^0|[^\d]|[.]/g, '')
			  this.$nextTick(() => {
			    this.myFormData.rrate= e.target.value
			  })
			},
			onSubmit() {
			  let myForm = this.myFormData
			  if(!myForm.arate || myForm.arate.length==0){
			  				this.$tip.alert('请填写巡检采集频率');
			  				return false
			  }
			  if(!myForm.rrate || myForm.rrate.length==0){
			  				this.$tip.alert('请填写基准采集频率');
			  				return false
			  }
			  
				console.log('myform',this.myFormData)
				this.$tip.loading();
				this.$http.put('/api/v1/appbusiness/two/setConfig',this.myFormData).then(res=>{
					console.log(res)
					this.$tip.loaded();
					if (res.data.success){
						this.$tip.toast('提交成功')
						 /* uni.navigateTo({
							url: '/pages/common/patrolstation'
						}) */
						let pages = getCurrentPages(); // 当前页面
						let beforePage = pages[pages.length - 2]; // 上一页
						uni.navigateBack({
						    success: function() {
						        beforePage.onLoad(); // 执行上一页的onLoad方法
						    }
						});
					}
				}).catch(()=>{
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
			}
		}
	}
</script>

<style>

</style>
